package 力扣._3152_特殊数组2;

import java.util.Arrays;

class Solution {
    public boolean[] isArraySpecial(int[] nums, int[][] queries) {
        //
        int len = nums.length;
        int[] dp = new int[len]; // dp[i]：以nums[i]为结尾的特殊数组的最大长度
        Arrays.fill(dp, 1);
        for(int i = 1;i < dp.length; i++){
            if( nums[i]%2 != nums[i-1]%2)
                dp[i] = dp[i-1] +1;
        }

        boolean[] r = new boolean[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int l_i = queries[i][0];
            int r_i = queries[i][1];
            // 特殊数组的子数组一定是特殊数组， 则只要r[i]的长度小于以nums[r_i]为结尾的特殊数组的最大长度, 其也就是特殊数组
            r[i] = r_i-l_i+1 <= dp[i];
        }
        return r;

    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,4};
        int[][] queries = new int[][]{{0,1}};
        boolean[] arraySpecial = new Solution().isArraySpecial(nums, queries);
        System.out.println(arraySpecial[0]);
    }
}